package org.dandsoft.blackbox.laboratory.tools.view;

import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 02.04.2009 20:25:29
 */
public class ValueColorSpec {

    public static final int SCALE_SIZE = 1000;
    private static final Color[] scaleColor = new Color[SCALE_SIZE];

    static {
        final int AFTER_RED = 1;
        final int BEFORE_GREEN = 2;
        final int AFTER_GREEN = 3;
        final int BEFORE_BLUE = 4;
        int state = AFTER_RED;
        int red = 255;
        int green = 0;
        int blue = 0;
        for (int i = 0; i < SCALE_SIZE; i++) {
            if (AFTER_RED == state) {
                green++;
            } else if (BEFORE_GREEN == state) {
                red--;
            } else if (AFTER_GREEN == state) {
                blue++;
            } else if (BEFORE_BLUE == state) {
                green--;
            }

            Color color;
            try {
                color = new Color(red, green, blue);
                scaleColor[i] = color;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (green == 255 && red == 255 && state == AFTER_RED) {
                state = BEFORE_GREEN;
            } else if (green == 255 & red == 0 && state == BEFORE_GREEN) {
                state = AFTER_GREEN;
            } else if (green == 255 && blue == 255 && state == AFTER_GREEN) {
                state = BEFORE_BLUE;
            }
        }
    }


    public static Color getColor(int index) {
        return scaleColor[index];
    }
}
